package org.crawler;

import java.util.LinkedList;
import java.util.Queue;

import org.crawler.task.TaskCenter;
import org.crawler.taskobj.WebUrl;

public abstract class AbstractController {
	
	public abstract void run();
	
	private Queue<WebUrl> seedQueue=new LinkedList<WebUrl>(); 
	
	
	
	public String getHost(String ssss)
	{
		if(ssss.startsWith("http"))
		{
			int beg=ssss.indexOf("//");
			int end=ssss.indexOf("/",beg+2);
			return ssss.substring(beg+2, end);
		}else if(!ssss.startsWith("/"))
		{
			int end=ssss.indexOf("/",0);
			return ssss.substring(0, end);
		}
		return null;
	}
	
	public void setUrlSeed(Queue<String> urlQueue)
	{
		String url="";
		WebUrl webUrl=null;
		while(urlQueue.size()>0)
		{
			url=urlQueue.poll();
			webUrl=new WebUrl(url,0);
			
			if(getHost(webUrl.getUrl())==null)
			{
				System.out.println("Error Seed"+webUrl.getUrl());
			}else
			{
				webUrl.setHost(getHost(webUrl.getUrl()));
				System.out.println(webUrl.getHost());
				seedQueue.add(webUrl);
			}
			

		}

	}

}
